cap cd "/Users/ddgueorg/Dropbox/C-GAP/C-GAP Replication Files/Coding"
cap cd "C:\Users\ejm5\Dropbox\C-GAP\C-GAP Replication Files\Coding"

clear all
set more off 
*****

**Data Composition**
cd "../Data"

**Import Freedom House Data**
use "Freedom House.dta", clear
* Generate country codes 
kountry country, from(other) stuck 
rename _ISO3N_ iso3n
kountry iso3n, from(iso3n) to(cown) 
rename _COWN_ ccode
*Reconstruct Freedom House composite variable
g pr=7 if political<6
replace pr=6 if political>5
replace pr=5 if political>11
replace pr=4 if political>17
replace pr=3 if political>23
replace pr=2 if political>29
replace pr=1 if political>35
replace pr=. if political==.

g cl=7 if civil <8
replace cl=6 if civil>7
replace cl=5 if civil>16
replace cl=4 if civil>25
replace cl=3 if civil>34
replace cl=2 if civil>43
replace cl=1 if civil>52
replace cl=. if civil==.

g freedom=(pr+cl)/2

**Merge with Chinese Internet Data**
merge m:m ccode year using "internet_china.dta"
drop _merge

**Merge with Penn Tabs**
merge m:m ccode year using "pwt80.dta"
g gdp_pc= rgdpna/pop
drop _merge

**Merge with ICRG Quality of Governance**
merge m:m ccode year using "qog_p.dta"
drop _merge

**Internet multiply**
replace pen=pen*100

**Output**
cd "../Results"

preserve 
drop if year<1976
drop if year>2012
replace freedom=6.5 if ccode==710 & year==2002
lowess freedom year if ccode==710, ylabel(1(1)7) lineopts(lpattern(dash)) scheme(s1mono) xtitle(Year) ylabel(, angle(horizontal)) ///
note(, size(zero)) xtitle(, size(zero)) title (Freedom House Index, size(msmall)) ytitle(Higher = less democracy) name(freedom)
lowess p_polity2 year if ccode==710, lineopts(lpattern(dash)) ylabel(-8(.4)-6) scheme(s1mono) xtitle(, size(zero)) ylabel(, angle(horizontal)) ///
note(, size(zero)) xtitle(, size(zero)) title(Polity IV index, size(msmall)) ytitle(Lower = less democracy) name(polity)
lowess gdp_pc year if ccode==710,  lineopts(lpattern(dash)) scheme(s1mono) xtitle(Year) ylabel(, angle(horizontal)) ///
note(, size(zero)) xtitle(, size(zero)) title(GDP per capita, size(msmall)) ytitle(Chinese RMB) name(gdp_pc)
lowess pen year if ccode==710,  lineopts(lpattern(dash)) scheme(s1mono) xtitle(Year) ylabel(, angle(horizontal)) ///
note(, size(zero)) xtitle(, size(zero)) title(Internet penetration, size(msmall)) ytitle(Proportion w/internet access) name(internet)

graph combine gdp_pc internet freedom polity
graph save "fig_1.1_China_Puzzle.gph", replace


